<?php 

/**
 * Abstract class for geocoder adapters
 * 
 * @category Noginn
 * @package Noginn_Geocoder
 */
abstract class Noginn_Geocoder_Adapter_Abstract
{
    /**
     * Geocode the address
     *
     * @param string|array $address 
     * @return Noginn_Geocoder_LocationList
     */
    abstract public function geocode($address);
    
    protected function _buildQuery($address)
    {
        if (is_array($address)) {
            $queryParts = array();
            if (array_key_exists('street', $address)) {
                $queryParts[] = $address['street'];
            }
            if (array_key_exists('city', $address)) {
                $queryParts[] = $address['city'];
            }
            if (array_key_exists('region', $address)) {
                $queryParts[] = $address['region'];
            }
            if (array_key_exists('postalCode', $address)) {
                $queryParts[] = $address['postalCode'];
            }
            if (array_key_exists('countryCode', $address)) {
                $queryParts[] = $address['countryCode'];
            }
            
            return implode(', ', $queryParts);
        }
        else if (is_string($address)) {
            return $address;
        }
        
        throw new Zend_Exception('Must be an address string or array of parts');
    }
}